<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  website
 */

class m_website_actions_block_DashBoardSiteAction extends m_backoffice_extends_Action
{
	public function execute()
	{
            //Nombre de site
            $documentProvider = f_document_Provider::getInstance();
            $nbSites = $documentProvider->loadDocuments('modules_website/website')->count();
            //Nombre de site
            $nbPages = $documentProvider->loadDocuments('modules_website/page')->count();
            //Website List
            $listSites = $documentProvider->loadDocuments('modules_website/website')->retrieveDocuments();

            //Unvalidate document list            
            $tempDoc = Array();

            $tempService = m_backoffice_services_TempDocService::getInstance();
            $allDocs = $tempService->getAllTemporaryDocuments();

            foreach($allDocs as $doc)
            {
                if($doc->getModel() == 'modules_website/page')
                {
                    $original = f_document_Provider::getInstance()->getByModelAndUniqueId('website/Page', $doc->getUniqueId(), $doc->getLang());
                    $tempDoc[] = $original;
                }
            }

            $this->addToModel('tempDoc', $tempDoc);
            $this->addToModel('nbTempDoc', count($tempDoc));

            $this->addToModel('listSites', $listSites);
            $this->addToModel('nbSites', $nbSites);
            $this->addToModel('nbPages', $nbPages);

            $this->setView("success");
	}
    
	public function validate()
	{
		return $this->getUserContext()->hasRight(array("backoffice_accessBo", "backoffice_accessWebsite"));
	}
}